from src.math.vector import Vector
from pymunk.vec2d import Vec2d
import math

class MovementHelper:
    
    @staticmethod
    def isPointInRect(point, rect):
        px, py = point
        rx, ry, rw, rh = rect
        
        return px >= rx and px <= rx + rw and py >= ry and py <= ry + rh
 
    @staticmethod
    def intersect(rect1, rect2):
        r1x, r1y, r1w, r1h = rect1
        if MovementHelper.isPointInRect((r1x, r1y), rect2):
            return True
        if MovementHelper.isPointInRect((r1x + r1w, r1y), rect2):
            return True
        if MovementHelper.isPointInRect((r1x, r1y + r1h), rect2):
            return True
        if MovementHelper.isPointInRect((r1x + r1w, r1y + r1h), rect2):
            return True
        return False
    
    @staticmethod
    def distanceToPoint(vec, point):
        if not isinstance(vec, Vector):
            x, y = vec
            vec = Vector(x, y)
        if not isinstance(point, Vector):
            x, y = point
            point = Vector(x, y)
            
        return (point - vec).length()
    
    @staticmethod
    def deg2vec(degree):
        vec = Vec2d(0, -1)
        vec.rotate_degrees(-degree)
        vec.normalize_return_length()
        return vec
    